Xbasic

Array initialize_from_table Method

Syntax

V <array>.initialize_from_table( tablename as C [, filter as C [, order as C [, append as L [, columns as C]]]])

V <array>.initialize_from_table( tablename as C [, filter as C [, order as C ]] )

V <array>.initialize_from_table( table_pointer as P [, filter as C [, order as C ]] )

V <array>.initialize_from_table( map_table_pointer as P [, filter as C [, order as C ]] )

Arguments

tablenameCharacter

The fully qualified name of a table.

table_pointerPointer

A pointer to an open table.

map_table_pointerPointer

A pointer created with the TABLE.OPENMAP() method.

filterCharacter

Default = all records. A character filter expression that evaluates to a logical value. Selects records from the table.

orderCharacter

Default = record order. A character order expression that sorts selected records.

appendLogical

Logical

columnsCharacter

A CR-LF delimited list of fieldnames in the source table to use when populating the array.

Description

Initialize property array subfields from a table.

Discussion

The <array>.initialize_from_table() method loads field values from a table into a property array. If an optional filter and order parameter are specified, only records that satisfy the filter are loaded. The records are sorted based on the expression defined by order.

Example

Assume a table (Names.dbf) contains the following entries:

NameCityAgeHobby
JohnSudbury40Skiing
FrankBoston24Diving
JoanneLincoln28Karate

dim names[5] as P
Names.initialize_from_table("c:\program files\a5\data\name.dbf")

This initializes an array with a Name, City, Age and Hobby property:

? names.dump_properties("Name|City|Age|Hobby")
= John|Sudbury|40|Skiing
Frank|Boston|24|Diving
Joanne|Lincoln|28|Karate

To sort the array by city:

names.sort("", "city")

? names.dump_properties("Name|City|Age|Hobby")
= Frank|Boston|24|Diving
Joanne|Lincoln|28|Karate
John|Sudbury|40|Skiing

Filter and Order Expressions

The following example shows how to use filter and order expressions.

dim tbl as P
dim arr_count as N
dim indx as P
tbl = table.open("travel time")
query.filter = "office_time<>\"\" .and. start_time<>\"\" .and. date<>{}"
indx = tbl.query_create()
arr_count = indx.records_get()
indx.close()
tbl.close()
dim raw[arr_count] as P
raw.initialize_from_table("travel time", "office_time<>\"\" .and. start_time<>\"\" .and. date<>{}", "date")

See Also